#include "State.h"
#include "Camera.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>

namespace OCPP
{
	State::State(Camera& camera)
		:camera(camera)
	{
	}

	State::~State()
	{

	}

	Matrix4 viewProject;
	float farPlane = 100.0;

	void State::updateState(Shader& shader)
	{
		shader.setUniform1f("farPlane", farPlane);
		shader.setUniformMatrix4fv("camMatrix", camera.getViewProjectMatrix());
		shader.setUniform3fv("camPos", camera.getPosition());
		shader.setUniform3fv("lightPos", lightPos);
		shader.setUniform4fv("lightColor", lightColor);

		//Camera shadowCamera;
		//shadowCamera.setPosition(20.0 * lightPos);
		//shadowCamera.setLookAt(Vector3::ZERO);
		//viewProject = shadowCamera.getOthographicProjectMatrix() * shadowCamera.getViewMatrix();
		//shader.setUniformMatrix4fv("lightProjection", viewProject);


		//glm::vec3 lightPos2 = glm::vec3(0.0f, 10.0f, 0.0f);
		//glm::mat4 perspectiveProjection = glm::perspective(glm::radians(90.0f), 1.0f, 0.1f, farPlane);
		//glm::mat4 lightView = glm::lookAt(lightPos2, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
		//glm::mat4 lightProjection2 = perspectiveProjection * lightView;
		//shader.setUniformMatrix4fv("lightProjection", lightProjection2);


		// Matrices needed for the light's perspective on all faces of the cubemap
		//glm::mat4 shadowProj = glm::perspective(glm::radians(90.0f), 1.0f, 0.1f, farPlane);
		//glm::mat4 shadowTransforms[] =
		//{
		//	shadowProj * glm::lookAt(lightPos2, lightPos2 + glm::vec3(1.0, 0.0, 0.0), glm::vec3(0.0, -1.0, 0.0)),
		//	shadowProj * glm::lookAt(lightPos2, lightPos2 + glm::vec3(-1.0, 0.0, 0.0), glm::vec3(0.0, -1.0, 0.0)),
		//	shadowProj * glm::lookAt(lightPos2, lightPos2 + glm::vec3(0.0, 1.0, 0.0), glm::vec3(0.0, 0.0, 1.0)),
		//	shadowProj * glm::lookAt(lightPos2, lightPos2 + glm::vec3(0.0, -1.0, 0.0), glm::vec3(0.0, 0.0, -1.0)),
		//	shadowProj * glm::lookAt(lightPos2, lightPos2 + glm::vec3(0.0, 0.0, 1.0), glm::vec3(0.0, -1.0, 0.0)),
		//	shadowProj * glm::lookAt(lightPos2, lightPos2 + glm::vec3(0.0, 0.0, -1.0), glm::vec3(0.0, -1.0, 0.0))
		//};

		//shader.setUniformMatrix4fv("shadowMatrices[0]",shadowTransforms[0]);
		//shader.setUniformMatrix4fv("shadowMatrices[1]",shadowTransforms[1]);
		//shader.setUniformMatrix4fv("shadowMatrices[2]",shadowTransforms[2]);
		//shader.setUniformMatrix4fv("shadowMatrices[3]",shadowTransforms[3]);
		//shader.setUniformMatrix4fv("shadowMatrices[4]",shadowTransforms[4]);
		//shader.setUniformMatrix4fv("shadowMatrices[5]",shadowTransforms[5]);
		//lightPos = {0,10,0};
		//shader.setUniform3fv("lightPos", lightPos);
	}
}